//
//  MethodTool.m
//  Learn
//
//  Created by zyl on 2024/4/3.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "MethodTool.h"

@implementation MethodTool
+ (double)getTextHeightWithStr:(NSString *)str font:(UIFont *)font ViewWidth:(double)width
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil];
    return rect.size.height + 1;
}
+ (double)getTextWidthWithStr:(NSString *)str font:(UIFont *)font ViewHeight:(double)height
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil];
    return rect.size.width + 1;
}
+ (NSString *)dateToStyle1WithDate:(double)date;//yyyy-MM-dd hh:mm
{
    NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    NSString * dateString = [dateFormatter stringFromDate:date1];
    return dateString;
}
+ (NSDate *)dateStrToDateWithStr:(NSString *)date//yyyy-MM-dd hh:mm
{
   
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];

    return [dateFormatter dateFromString:date];
}
+ (void)callWithMobileNumber:(NSString *)mobile
{
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",mobile]]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",mobile]]];
    }
    
}
+ (void)getCookieWithwebView:(WKWebView *)web success:(void(^)(BOOL success))successBlock
{
    //网页加载完成取出 cookies

    WKHTTPCookieStore *store = web.configuration.websiteDataStore.httpCookieStore;
    [store getAllCookies:^(NSArray<NSHTTPCookie *> * _Nonnull cookie) {
       
        NSHTTPCookie *cooki= cookie.lastObject;
        if ([cooki value]) {
            LTApp.cookie = [NSString stringWithFormat:@"%@=%@",[cooki name],[cooki value]];
        }
        successBlock(YES);
    }];
}
@end
